package com.lqg.bookLibrary;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

public class CodeGenerator {
    public static void main(String[] args) {
        FastAutoGenerator.create(
                "jdbc:mysql://localhost:3306/book_library?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=Asia/Shanghai",
                        "root", "5413")
                .globalConfig(builder -> {
                    builder.author("prodigal_lqg") // 设置作者
                            .commentDate("yyyy-MM-dd ")
                            .outputDir("E:\\graduation_project\\book-recommendation\\book_library\\src\\main\\java\\"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.lqg.bookLibrary") // 设置父包名
                            .entity("pojo")
                            .service("service")
                            .serviceImpl("service.impl")
                            .mapper("mapper")
                            .controller("controller")
                            .other("other")
                            .pathInfo(Collections.singletonMap(OutputFile.xml,
                                    "E:\\graduation_project\\book-recommendation\\book_library\\src\\main\\resources\\mapper\\")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    //"admins","books","borrow","collect",
                    //        "score","stock","type","users","roles","avg_score"
                    builder
                            .addInclude("menu")// 设置需要生成的表名
                            .entityBuilder()
                            .enableLombok()
                            .enableTableFieldAnnotation()

                            .controllerBuilder()
                            .enableHyphenStyle()
                            .enableRestStyle()

                            .mapperBuilder()
                            .enableMapperAnnotation()
                    ;
                })
                // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
